#!/bin/bash

echo "启动新版价格策略分析平台..."
echo "时间: $(date)"

source activate ml

# 设置环境变量
export PYTHONPATH="${PYTHONPATH}:$(pwd)"

# 创建必要的目录
mkdir -p logs
mkdir -p data
mkdir -p cache

# 检查Python环境
if command -v python3 &> /dev/null; then
    PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
    PYTHON_CMD="python"
else
    echo "错误: 未找到Python环境"
    exit 1
fi

echo "使用Python命令: $PYTHON_CMD"

# 检查依赖
echo "检查依赖包..."
$PYTHON_CMD -c "import streamlit, pandas, numpy, matplotlib, seaborn" 2>/dev/null
if [ $? -ne 0 ]; then
    echo "警告: 部分依赖包可能未安装，请运行 pip install -r requirements.txt"
fi

# 启动应用
echo "启动Streamlit应用..."
echo "访问地址: http://localhost:8502"
echo "按 Ctrl+C 停止应用"

$PYTHON_CMD -m streamlit run new_app.py \
    --server.port 8502 \
    --server.address 0.0.0.0 \
    --server.headless true \
    --browser.gatherUsageStats false

echo "应用已停止"
echo "时间: $(date)"